class_name WeaponC_Cursor
extends WeaponC

@export var scale_vec2:Vector2 = Vector2.ONE
@export var correct_scale:float = 1.0
@export var cursor: Sprite2D
var default_scale:Vector2
func init_component(weapon:Weapon):
	super.init_component(weapon)
	default_scale = cursor.scale
	cursor.visible = false
func equip():
	super.equip()
	Input.mouse_mode = Input.MOUSE_MODE_CONFINED_HIDDEN
	cursor.visible = true
func unequip():
	Input.mouse_mode = Input.MOUSE_MODE_CONFINED
	cursor.visible = false
	super.unequip()
func discard():
	super.discard()
	
func _init() -> void:
	weapon_component_name = "WeaponC_Cursor"
func _process(delta: float) -> void:
	if not weapon or not weapon.enable or not enable or not inited:
		return
	var dis := (get_global_mouse_position() - global_position).length()
	var diameter := dis * sin(deg_to_rad(weapon.weapon_data.scattering_angle/2)) * 0.1 * correct_scale
	diameter = clamp(diameter,scale_vec2.x,scale_vec2.y)
	cursor.global_scale = default_scale * Vector2(diameter,diameter)
	cursor.global_position = get_global_mouse_position()
	var is_gaming_state:bool = GameManager.get_cur_game_state() == GameEnum.GameState.Gaming
	Input.mouse_mode = Input.MOUSE_MODE_CONFINED_HIDDEN if is_gaming_state else Input.MOUSE_MODE_CONFINED
	cursor.visible = is_gaming_state
